//
//  MyCollectionTableViewController.m
//  ITHome
//
//  Created by lanou3g on 15/7/18.
//  Copyright (c) 2015年 YAX. All rights reserved.
//

#import "MyCollectionTableViewController.h"
#import "FMDBManageModel.h"
#import "FMDBManage.h"
#import "HeaderWebViewController.h"
#import "MyCollectionTableViewController.h"

@interface MyCollectionTableViewController ()
@property(nonatomic,strong)NSMutableArray *modelArray;


@end

@implementation MyCollectionTableViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.modelArray = [NSMutableArray array];
    self.modelArray = [FMDBManage getAllInfo];
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我的收藏";
    // 标题颜色
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor RGBColor:71 green:128 blue:208 alpha:1]}];
    // 导航栏颜色
    self.navigationController.navigationBar.barTintColor = [UIColor RGBColor:71 green:128 blue:208 alpha:1];
    // 标题颜色
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    // 返回
    UIBarButtonItem *leftBackButton = [UIBarButtonItem itemWithTarget:self Action:@selector(backAction) image:@"home_back" highImage:@"home_back_highlighted"];
    self.navigationItem.leftBarButtonItem = leftBackButton;
    
    self.tableView.tableFooterView = [[UIView alloc] init];
    
}

- (void)backAction
{
    [self dismissViewControllerAnimated:YES completion:nil];    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return self.modelArray.count;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    FMDBManageModel *model = self.modelArray[indexPath.row];
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    HeaderWebViewController *header = [[HeaderWebViewController alloc]init];
    header.urlString = model.urlString;
    header.urlId = model.urlId;
    header.commentsCount = model.commentsCount;
    header.url = [NSString stringWithFormat:@"http://36kr.com/p/%@.html", model.urlId]; // 分享的Url
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:header];
    nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:nav animated:YES completion:nil];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView registerClass:[ITHomePublicTableViewCell class] forCellReuseIdentifier:@"collection"];
    ITHomePublicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"collection"];
    FMDBManageModel *model = self.modelArray[indexPath.row];
    [cell setCollectionedModel:model];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kScreenIp6(90);
}

#pragma mark - 内容警告触发方法
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    [[SDImageCache sharedImageCache] clearMemory];
}


@end
